﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MetroFramework;
using MetroFramework.Forms;

namespace Coffee_Restaurant
{
    public partial class CustomMessageBox : MetroForm
    {
        public CustomMessageBox()
        {
            InitializeComponent();
        }

        static CustomMessageBox _msgBox;
        private static DialogResult _result = System.Windows.Forms.DialogResult.No;

        public static DialogResult Show(string text, string caption, string type, MetroColorStyle color)
        {
            _msgBox = new CustomMessageBox();
            switch (type)
            {
                case "confirm":
                    _msgBox.btnLeft.Text = "OK";
                    _msgBox.btnLeft.Visible = true;
                    _msgBox.AcceptButton = _msgBox.btnLeft;
                    _msgBox.btnLeft.Click += btnOk_Click;
                    _msgBox.Style = MetroColorStyle.Red;
                    _msgBox.btnRight.Text = "Hủy";
                    _msgBox.btnRight.Visible = true;
                    _msgBox.CancelButton = _msgBox.btnRight;
                    _msgBox.btnRight.Click += btnCancel_Click;
                    break;
                case "alert":
                    _msgBox.btnRight.Text = "OK";
                    _msgBox.btnRight.Visible = true;
                    _msgBox.AcceptButton = _msgBox.btnRight;
                    _msgBox.btnRight.Click += btnOk_Click;
                    _msgBox.Style = MetroColorStyle.Default;
                    break;
            }
            _msgBox.lblText.Text = text;
            _msgBox.Text = caption;
            _msgBox.Style = color;
            _msgBox.ShowDialog();
            return _result;
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Enter)
            {
                _result = DialogResult.Yes;
                _msgBox.Close();
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        private static void btnOk_Click(object sender, EventArgs e)
        {
            _result = DialogResult.Yes;
            _msgBox.Close();
        }
        private static void btnCancel_Click(object sender, EventArgs e)
        {
            _result = DialogResult.No;
            _msgBox.Close();
        }
    }
}
